<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
      <el-form-item>
        <el-button type="primary" plain @click="openForm('create')">
          <Icon icon="ep:upload" class="mr-5px" /> 上传简历
        </el-button>

      </el-form-item>
    </el-form>
  </ContentWrap>


  <!-- 列表 -->
  <ContentWrap>

    <div class="mt-24">
      <el-row :gutter="20">
        <el-col v-for="(item, index) in list" :key="index" :span="12">
          <el-card class="mb-10" shadow="hover" >
            <template #header>
              <div class="card-header" style="text-align: center;">
                <span>{{ item.resumeName }}</span>
              </div>
            </template>
            <div>
              <PDFView :pdf-url="item.resumePath" :show-all="false"/>
            </div>
            <template #footer>
              <div style="text-align: right">
                <el-link  type="primary" download :href="item.resumePath" :underline="false" target="_blank" style="margin-right:13px;">下载</el-link>
                <el-button link type="primary" @click="resumeOpenForm('update', item.id)">
                    编辑
                  </el-button>
                  <el-button link type="danger" @click="handleDelete(item.id)" >
                    删除
                  </el-button>
              </div>
                  
              </template>
          </el-card>
        </el-col>
      </el-row>
    </div>

   
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <ResumeInfoForm ref="resumeFormRef" @success="getList" />
  <ResumeInfoFileForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import { ResumeInfoApi, ResumeInfoVO } from '@/api/dbit/resumeinfo'
import ResumeInfoForm from './ResumeInfoForm.vue'
import ResumeInfoFileForm from './ResumeInfoFileForm.vue'
import PDFView from "./ResumePdfView.vue"

/** 简历信息 列表 */
defineOptions({ name: 'ResumeInfo' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化
const loading = ref(true) // 列表的加载中
const list = ref<ResumeInfoVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  resumeName: undefined,
  resumePath: undefined,
  userId: undefined,
  createTime: []
})
const queryFormRef = ref() // 搜索的表单
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await ResumeInfoApi.getResumeInfoPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const resumeFormRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}
const resumeOpenForm = (type: string, id?: number) => {
  resumeFormRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await ResumeInfoApi.deleteResumeInfo(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch { }
}




/** 初始化 **/
onMounted(() => {
  getList()
})
</script>